package com.bbgwap.controller;


import com.bbgwap.base.BaseConfig;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by lixiang01 on 3/9/2017.
 */
@Controller
public class WXController extends BaseController {

    @RequestMapping(value = {"webadmin/wx"},method = RequestMethod.GET, produces = BaseConfig.CHARSET)
    public void showPage(@RequestParam(value = "echostr",required = false) String echostr ,PrintWriter out){
        if (echostr != null) {
            logger.info("来自微信服务器的请求："+echostr);
            out.print(echostr);
        }else{
            logger.info("来自微信服务器的请求为空");
        }
        out.flush();
        out.close();
    }

    @RequestMapping(value = {"webadmin/wx"},method =  RequestMethod.POST , produces = BaseConfig.CHARSET)
    public void dispose(HttpServletRequest request, HttpServletResponse response,PrintWriter out)
            throws IOException {
        /* 消息的接收、处理、响应 */

        // 将请求、响应的编码均设置为UTF-8（防止中文乱码）
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        // 调用核心业务类接收消息、处理消息
       // String respMessage = CoreService.processRequest(request);
        logger.info("get in post");
        // 响应消息

        out.print("I got you");
        out.flush();
        out.close();
    }
}
